Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

245
Views
I want the animation to work when i hover on the "a" element?

I used bootstrap. Here is my code , I want when mouseover an img or a element to make animation work also when mouseleave animation stop.

.progress-bar {
  animation: pr 2s infinite;
}

@keyframes pr {
  0% {
    width: 0;
    color: red;
  }
  10% {
    background-color: blue;
  }
  20% {
    background-color: black;
  }
  30% {
    background-color: yellow;
  }
  40% {
    background-color: tomato;
  }
  50% {
    width: 100%;
    background-color: violet;
  }
  60% {
    background-color: rgb(184, 145, 145);
  }
  70% {
    background-color: white;
  }
  80% {
    background-color: rgb(0, 255, 234);
  }
  100% {
    width: 0;
    background-color: red;
  }
}
<div style="margin-top: 50px" data-aos="fade-in" class="choosebybrand">
  <div class="samsung">
    <a href="samsung.html" class="buki">
      <div class="frontimage">
        <img src="images/samsung.png" height="232px" width="115px" alt="">
      </div>
      <h3>Samsung</h3>
    </a>

  </div>
  <div class="progress">
    <div class="progress-bar"></div>
  </div>

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Here's the code UPDATED

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <style type="text/css">
    @keyframes pr {
        0% {
            width: 0;
            color: red;
        }
        10% {
            background-color: blue;
        }
        20% {
            background-color: black;
        }
        30% {
            background-color: yellow;
        }
        40% {
            background-color: tomato;
        }
        50% {
            width: 100%;
            background-color: violet;
        }
        60% {
            background-color: rgb(184, 145, 145);
        }
        70% {
            background-color: white;
        }
        80% {
            background-color: rgb(0, 255, 234);
        }
        100% {
            width: 0;
            background-color: red;
        }
    }
    .hover-box .progress .progress-bar {
        height: 20px;
        width: 100%;
    }
    .hover-box .content:hover + .progress .progress-bar {
        background: red;
        animation: pr 2s infinite;
    }

</style>
</head>
<body>

    
    <div class="hover-box">
        <div class="content">
            <a href="#!">Hover me</a>
        </div>
        <div class="progress">
            <div class="progress-bar"></div>
        </div>
    </div>
</body>
</html>

about 4 years ago · Juan Pablo Isaza Report

0

Your progress-bar requires an height to be seen.

example:

/* do you need the progressbar to be as wide as the picture box ?*/


/* if yes, uncomment below selector & rule */


/* .choosebybrand {
display:inline-block; 
 }*/

.choosebybrand:hover ~ .progress .progress-bar {
  animation: pr 2s infinite;
  height: 1em;
}

@keyframes pr {
  0% {
    width: 0;
    color: red;
  }
  10% {
    background-color: blue;
  }
  20% {
    background-color: black;
  }
  30% {
    background-color: yellow;
  }
  40% {
    background-color: tomato;
  }
  50% {
    width: 100%;
    background-color: violet;
  }
  60% {
    background-color: rgb(184, 145, 145);
  }
  70% {
    background-color: white;
  }
  80% {
    background-color: rgb(0, 255, 234);
  }
  100% {
    width: 0;
    background-color: red;
  }
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css" rel="stylesheet" />
<div style="margin-top: 50px" data-aos="fade-in" class="choosebybrand">
  <div class="samsung">
    <a href="samsung.html" class="buki">
      <div class="frontimage">
        <img src="https://dummyimage.com/150x100&text=samsung" alt="">
      </div>
      <h3>Samsung</h3>
    </a>

  </div>
</div>
<div class="progress">
  <div class="progress-bar"></div>
</div>

about 4 years ago · Juan Pablo Isaza Report

0

You can't do exactly as required in the question using just CSS as the anchor and img elements are neither parents of the progress bar nor are they siblings. CSS does not allow going 'up' and then down again.

What you can do is sense the hover on an ancestor element of the anchor and img elements which also is a sibling of the progress element and get the animation going on the progress bar then.

.samsung {
  display: inline-block;
}

.samsung:hover~.progress .progress-bar {
  animation: pr 2s infinite;
}

.progress {
  width: 100vw;
}

.progress-bar {
  height: 2px;
  width: 100vw;
  background-color: magenta; /* added so something is seen when no hover */
}

@keyframes pr {
  0% {
    width: 0;
    color: red;
  }
  10% {
    background-color: blue;
  }
  20% {
    background-color: black;
  }
  30% {
    background-color: yellow;
  }
  40% {
    background-color: tomato;
  }
  50% {
    width: 100%;
    background-color: violet;
  }
  60% {
    background-color: rgb(184, 145, 145);
  }
  70% {
    background-color: white;
  }
  80% {
    background-color: rgb(0, 255, 234);
  }
  100% {
    width: 0;
    background-color: red;
  }
}
<div style="margin-top: 50px" data-aos="fade-in" class="choosebybrand">
  <div class="samsung">
    <a href="samsung.html" class="buki">
      <div class="frontimage">
        <img src="images/samsung.png" height="232px" width="115px" alt="">
      </div>
      <h3>Samsung</h3>
    </a>

  </div>
  <div class="progress">
    <div class="progress-bar"></div>
  </div>

Note: the snippet had to add height dimension so the progress bar could be seen.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!